<?php $this->placeholder('select_fanpages')->captureStart(Zend_View_Helper_Placeholder_Container_Abstract::SET) ?>
<?php $arrPageList    = $this->social->getPageList(); ?>
<?php if( !empty($arrPageList) ):?>
<div class="sm_select_fanpage forie">
<form action="post">
<?php
    $id_page              = Zend_Controller_Front::getInstance()->getRequest()->getParam('id_page',null);
    $arrOptions     = array();
    $arrCommon      = array(
		'module'				=> 'contest',
		'controller'			=> 'manage',
        'action'                => 'list'
    );
    foreach(array(''=>'- All Fan Pages -')+$arrPageList as $key => $value)
    {
        $arrOptions[$this->url(array_merge($arrCommon,array('id_page' => !empty($key)?$key:null)),null,true)] = $value;
    }
    $element = new Zend_Form_Element_Select('pages',
		array(
			'class'         => 'pages',
		)
	);
    $element->removeDecorator('Label');
    $element->removeDecorator('HtmlTag');
    $element->addMultiOptions($arrOptions);
    $element->setValue($this->url(array_merge($arrCommon,array('id_page' => $id_page)),null,true));
?>
<?php echo $element;?>
<?php if( !empty($id_page) && isset($arrPageList[$id_page]) ):?>
<span class="greenbutton view">
    <a href="<?php echo $this->social->getFanPageUrl($id_page);?>" target="_blank"><?php echo $this->translate('GO')?></a>
</span>
<?php endif;?>
</form>
</div>
<?php else:?>
<div id="btn_load_list_page" class="sm_select_fanpage">
	<span class="btn_green">
		<a onclick="void(0);" href="javascript:void(0);">
			<?php echo $this->translate('LOAD_MY_FANPAGES') ?>
		</a>
	</span>
</div>
<?php endif;?>
<script type="text/javascript">
jQuery("document").ready(function($){
	$("#pages").ymSelectPage({
        title	: '<?php echo $this->translate('Confirm this action') ?>',
        template:'<?php echo YouNet_Util::htmlToJs($this->social->render('dialogAskPageInstall'))?>',
        translate:{
            ADD_FANPAGE_SUCCESSFUL:"<?php echo $this->translate('ADD_FANPAGE_SUCCESSFUL')?>"
        }
    });
    
	Social.bind('#btn_load_list_page', 'click', function(e){
		Social.redirect('<?php echo $this->socialUrl();?>');
	},{
        scope: 'manage_pages',
        content:'You need to authorize the manage page permission before you can load your Fan Pages.'
    });	
});
</script>
<?php $this->placeholder('select_fanpages')->captureEnd() ?>